yuan = {
    username: "yuan",
    age: 22,
    wx: "u82d1660a",
    fn: function () {
        console.log("fn ...")
    }
}

rain = {
    username: "rain",
    age: 12,
    wx: "u82d1660a",
    fn: function () {
        console.log("fn ...")
    }
}

eric = {
    username: "eric",
    age: 32,
    wx: "u82d1660a",
    fn: function () {
        console.log("fn ...")
    }
}

// 批量代理
function setProxyArr(proxyObjArr) {
    for (let i = 0; i < proxyObjArr.length; i++) {
        const objName = proxyObjArr[i];
        const handler = {
            get(target, property, receiver) {
                console.log("方法:", "get", "对象:", objName, "属性:", property, "属性类型：", typeof property, "属性值：", target[property], "属性值类型：", typeof target[property]);

                return target[property];
            },
            set(target, property, value, receiver) {
                console.log("方法:", "set", "对象:", objName, "属性:", property, "属性类型：", typeof property, "属性值：", value, "属性值类型：", typeof target[property]);
                return Reflect.set(target, property, value, receiver);
            }
        };
        // 检查并初始化对象
        let targetObject = global[objName] || {};  // 在 Node.js 环境中使用 global
        global[objName] = new Proxy(targetObject, handler);  // 在 Node.js 中使用 global
    }
}

setProxyArr(["yuan","rain","eric"])


//  源码执行
console.log(yuan.username)
console.log(yuan.wx)
yuan.age = 18
console.log(yuan.age)
// console.log(yuan.wx)
// console.log(yuan.fn())

console.log(rain.age)
console.log(rain.username)
console.log(rain.fn())

console.log(eric.age)